package com.sunriz.motordrive.utils;

import jssc.SerialPortException;

/**
 * ClassName: TxModbus
 * Package: com.sunriz.motordrive.utils
 * Description:
 *
 * @Author BuTang
 * @Create 2024/4/29 14:46
 * @Version 1.0
 */
public class TxModbus {

    public void inquireByModbus(byte[] bytes ,jssc.SerialPort serialPort) throws SerialPortException {
//        byte[] bytes = {1, 3, 0, 1, 0, 1};
        String s = Crc.Crc16(bytes);
        String substring = s.substring(0, 2);
        String substring1 = s.substring(2);
//        byte[] substringBytes = substring.getBytes();

        byte[] newBytes  = new byte[(bytes.length + 2)];
        System.arraycopy(bytes, 0, newBytes, 0, bytes.length);
        newBytes[newBytes.length - 2] = (byte) Integer.parseInt(substring, 16);
        newBytes[newBytes.length - 1] = (byte) Integer.parseInt(substring1, 16);
        serialPort.writeBytes(newBytes);

    }
}
